<!DOCTYPE html>
<html class="Content">
<head>
    <title>xUnit.js: Importing Dependencies</title>
    <link type="text/css" rel="Stylesheet" href="../../Style/documentation.css" />
</head>
<body>
    <h1>Importing Dependencies</h1>
    <p>
        To load the code that the tests need to exercise, xUnit.js provides two built-in file I/O mechanisms:
    </p>
    <h3>Import</h3>
    <p>
        The <strong>Import</strong> attribute accepts a file <em>path</em> argument, which, by default, is resolved relative to the location of the current test file.
    </p>
    <p>
        This is the mechanism used to load standard javascript files with common patterns, such as named functions, namespaced objects and classes, and global variable declarations.
        <span class="Code">
Function.RegisterNamespace("Test.xUnit.js");

[<strong>Import("../../Source/xUnit.js/Assert.js")</strong>]
[Fixture]
Test.xUnit.js.Assert=function(){

    [...]

}
        </span>
    </p>
    <h3>ImportJson</h3>
    <p>
        The <strong>ImportJson</strong> attribute behaves similarly, but accepts a second argument, <em>callback</em>, to collect JSON packets that would otherwise be declared without
        a reference variable. This can be useful to define complex known shapes in gold files, or to simulate server responses with well-known values.
        <span class="Code">
Function.RegisterNamespace("Test.ResponseParser");

[Fixture]
Test.ResponseParser=function(){
    var response=null;
    [<strong>ImportJson("../../Source/xUnit.js/Assert.js",function(path,result){
        response=result;
    })</strong>]
    [Fact]
    function ParsesKnownObjectsFromResponse(){

        [...]

    }

}    
        </span>
    </p>
</body>
</html>